﻿using Sidvall.Serialization;

namespace Sidvall.Reflection
{
	public class TypeItem
	{
		#region AssemblyName

		private string _AssemblyName = string.Empty;
		public string AssemblyName
		{
			get
			{
				return _AssemblyName;
			}
			set
			{
				value = Sidvall.Business.ValidationManager.GetValidString(value, false, null);
				_AssemblyName = value;
			}
		}


		#endregion
		#region TypeName

		private string _TypeName = string.Empty;
		public string TypeName
		{
			get
			{
				return _TypeName;
			}
			set
			{
				value = Sidvall.Business.ValidationManager.GetValidString(value, false, null);
				_TypeName = value;
			}
		}

		#endregion

		#region Parse

		public static TypeItem Parse(string typeName)
		{
			TypeItem item;
			string[] parts;

			if (string.IsNullOrWhiteSpace(typeName))
				return null;
			parts = typeName.Split(",", System.StringSplitOptions.RemoveEmptyEntries);
			item = new TypeItem()
			{
				TypeName = parts[0].Trim(),
			};
			if (parts.Length > 1)
				item.AssemblyName = parts[1].Trim();

			return item;
		}

		#endregion
	}
}
